﻿using System;

namespace NeroConnect.Network
{
	/// <summary>Factory for creating request objects for clients and listener objects for servers</summary>
	public interface IFactory
	{
		/// <summary>Initializes a new IRequest instance for the specified URL.</summary>
		/// <param name="requestUriString">The URI that identifies the Internet resource.</param>
		/// <returns>A IRequest for the specific URI scheme.</returns>
		/// <exception cref="System.NotSupportedException">The request scheme specified in requestUriString has not been registered.</exception>
		/// <exception cref="System.ArgumentNullException">requestUriString is null.</exception>
		/// <exception cref="System.Security.SecurityException">The caller does not have permission to connect to the requested URI or a URI that the request is redirected to.</exception>
		/// <exception cref="System.UriFormatException">The URI specified in requestUriString is not a valid URI.</exception>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "string")]
		IRequest CreateRequest(string requestUriString);

		/// <summary>Initializes a new IRequest instance for the specified URI scheme.</summary>
		/// <param name="requestUri">A System.Uri containing the URI of the requested resource.</param>
		/// <returns>An IRequest for the specified URI scheme.</returns>
		/// <exception cref="System.NotSupportedException">The request scheme specified in requestUri is not registered.</exception>
		/// <exception cref="System.ArgumentNullException">requestUri is null.</exception>
		/// <exception cref="System.Security.SecurityException">The caller does not have permission to connect to the requested URI or a URI that the request is redirected to.</exception>
		IRequest CreateRequest(Uri requestUri);

		/// <summary>Initializes a new instance of the IListener interface</summary>
		/// <param name="port">Port number to bind.</param>
		/// <returns>An IListener which can be used to listen and respond to incoming HTTP requests</returns>
		/// <exception cref="System.Net.HttpListenerException">A Windows function call failed. Check the exception's ErrorCode property to determine the cause of the exception. This exception is thrown if another IListener is already using this port.</exception>
		MiniHttpServer.IHttpListener CreateListener(int port);

		/// <summary>Creates an object for UDP based communication</summary>
		/// <param name="endPoint">end point to which the udp client is bound</param>
		/// <returns>An IUdpClient for communicating over UDP bound to the provided end point</returns>
		/// <exception cref="System.ArgumentNullException">endPoint is null.</exception>
		/// <exception cref="System.Net.Sockets.SocketException">An error occurred when accessing the socket. See the Remarks section for more information.</exception>
		IUdpClient CreateUdpClient(System.Net.IPEndPoint endPoint);

		/// <summary>Creates an object for UDP based communication</summary>
		/// <param name="port">Port number to bind.</param>
		/// <param name="addressFamily">One of the System.Net.Sockets.AddressFamily values that specifies the addressing scheme of the socket.</param>
		/// <returns>An IUdpClient for communicating over UDP not bound to any end point.</returns>
		/// <exception cref="System.ArgumentException">addressFamily is not System.Net.Sockets.AddressFamily.InterNetwork or System.Net.Sockets.AddressFamily.InterNetworkV6.</exception>
		/// <exception cref="System.ArgumentOutOfRangeException">port is greater than System.Net.IPEndPoint.MaxPort or less than System.Net.IPEndPoint.MinPort. </exception>
		/// <exception cref="System.Net.Sockets.SocketException">An error occurred when accessing the socket. See the Remarks section for more information.</exception>
		IUdpClient CreateUdpClient(int port, System.Net.Sockets.AddressFamily addressFamily);

		/// <summary>Creates an object for UDP based communication</summary>
		/// <param name="port">Port number to bind.</param>
		/// <returns>An IUdpClient for communicating over UDP not bound to any end point.</returns>
		/// <exception cref="System.ArgumentException">addressFamily is not System.Net.Sockets.AddressFamily.InterNetwork or System.Net.Sockets.AddressFamily.InterNetworkV6.</exception>
		/// <exception cref="System.ArgumentOutOfRangeException">port is greater than System.Net.IPEndPoint.MaxPort or less than System.Net.IPEndPoint.MinPort. </exception>
		/// <exception cref="System.Net.Sockets.SocketException">An error occurred when accessing the socket. See the Remarks section for more information.</exception>
		IUdpClient CreateUdpClient(int port);
	}
}
